//
//  GGNavViewController.m
//  DDLock
//
//  Created by ios on 2017/12/25.
//  Copyright © 2017年 saiyi. All rights reserved.
//

#import "GGNavViewController.h"

@interface GGNavViewController ()<UIGestureRecognizerDelegate>

@end

@implementation GGNavViewController

- (void)viewDidLoad {
    [super viewDidLoad];

     self.interactivePopGestureRecognizer.delegate = self;
    
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    if (self.childViewControllers.count >= 1){

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"return_8"] forState:UIControlStateNormal];
        [button sizeToFit];
        button.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [button addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];

        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
        [view addSubview:button];
        button.backgroundColor  = [UIColor purpleColor];
        view.backgroundColor = [UIColor redColor];
        button.frame = view.bounds;
        UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:view];
        viewController.navigationItem.leftBarButtonItem = leftItem;
        viewController.hidesBottomBarWhenPushed = YES;
        
    }
    
    [super pushViewController:viewController animated:animated];

}

- (void)clickBack {

    [self popViewControllerAnimated:YES];

}

- (BOOL)gestureRecognizerShouldBegin:(nonnull UIGestureRecognizer *)gestureRecognizer{
    
    
    return self.childViewControllers.count > 1;
}


@end
